/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package otros;

import javax.swing.table.DefaultTableModel;

/**
 *
 * @author FERRETERIA
 */
public class MiTableModel extends DefaultTableModel{

    private Class [] type;
    private Boolean [] editable;
    
    public MiTableModel() {
        super();
    }
    
    public MiTableModel (Object [][] valores, String [] cab, Class[] tipos,
                    Boolean [] edits) {
        super(valores, cab);
        type = tipos;
        editable = edits;
    }
    
     public MiTableModel (Object [][] valores, String [] cab) {
         super(valores, cab);
     }
    
    
    @Override
    public Class<?> getColumnClass(int i) {
        Class valor = null;
        try {
            if (getType() != null)
                valor = getType()[i];
            else if ((i >= 0) && (i < getColumnCount()))
                if (getValueAt(0, i) != null)
                    valor = getValueAt(0, i).getClass();

            if (valor == null)
                valor = Object.class;
        } catch(Exception e) {
            valor = Object.class;
        }
        return valor;
        //return super.getColumnClass(i); //To change body of generated methods, choose Tools | Templates.
    }
   
    @Override
    public boolean isCellEditable (int row, int column) {
        // Aquí devolvemos true o false según queramos que una celda
        // identificada por fila,columna (row,column), sea o no editable
        if (getEditable() == null)
            return false;
        if (column < getEditable().length)
            return getEditable()[column];
        return false;
    }

    @Override
    public void addRow(Object[] os) {
        super.addRow(os);
    }

    
    
    
    public Class[] getType() {
        return type;
    }

    public void setType(Class[] type) {
        this.type = type;
    }

    public Boolean[] getEditable() {
        return editable;
    }

    public void setEditable(Boolean[] editable) {
        this.editable = editable;
    }
    
}
